#include "NetworkAccessManager.h"
#include <QNetworkReply>
#include <QFile>
#include <QUrl>
#include <QDir>
#include <qDebug>

namespace TC
{
    namespace Network
    {
        NetworkAccessManager::NetworkAccessManager(QObject *parent)
            : QNetworkAccessManager(parent)
        {
            QNetworkDiskCache *cache = new QNetworkDiskCache(parent);
            qDebug() << "setting up my network access manager";

#ifdef Q_OS_ANDROID
            cache->setCacheDirectory("/sdcard/tcommunity/cache");
#elif defined(Q_OS_WIN)
            cache->setCacheDirectory("cache");
#endif // Q_OS_WIN

            this->setCache(cache);
        }
        NetworkAccessManager::~NetworkAccessManager()
        {

        }

        QNetworkReply * NetworkAccessManager::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData /*= nullptr*/)
        {
            QNetworkRequest newReq = request;
            //newReq.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
            return QNetworkAccessManager::createRequest(op, request, outgoingData);
        }
    }
}
